pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "curl") {
	restore()
}


target(restore: "The implementation task") {
	depends( initCloudToolsService)

   	cloudToolsService.withCluster {manager, clusterName, cluster->
	    if(System.getProperty("cloudtools.s3.path") != null){
			def s3Path = System.getProperty("cloudtools.s3.path")
		      	cluster.dbRestore(s3Path)
			event('StatusFinal', ['Finished with db-restore on ' + s3Path])
		}else{
			event('StatusError', ['You must specify cloudtools.s3.path.  Example:\ngrails -Dcloudtools.s3.path=<path> cloud-tools-db-restore'])
		}
	}
}
